package com.beehoo.dcportal.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.log4j.Logger;

import com.beehoo.dcportal.common.base.BaseDao;
import com.beehoo.dcportal.common.base.BaseException;
import com.beehoo.dcportal.dao.IComplaintDao;
import com.beehoo.dcportal.model.ComplaintBean;

public class ComplaintDaoImpl extends BaseDao implements IComplaintDao {
	private static final Logger logger = Logger.getLogger(ComplaintDaoImpl.class);

	@Override
	public String addComplaint(ComplaintBean complaintBean)
			throws BaseException {
		String queId = null;
		try {
			queId = (String) getSqlMapClient().insert("portal-complaint.addComplaint", complaintBean);
			logger.info("投诉上报-添加投诉上报|#" +
					"[中心编号："+complaintBean.getStreetId()+"]" +
					"[事件类型："+complaintBean.getQueType()+"]" +
					"[事件内容："+complaintBean.getQueContent()+"]" +
					"[事件发生地："+complaintBean.getQueAddr()+"]" +
					"[服务条线："+complaintBean.getServLine()+"]" +
					"[服务子条线："+complaintBean.getServSubline()+"]" +
					"[投诉人："+complaintBean.getQueAuthor()+"]" +
					"[手机号："+complaintBean.getAuthorPhone()+"]" +
					"[固定电话："+complaintBean.getAuthorTel()+"]" +
					"[身份证："+complaintBean.getAuthorIdcard()+"]" +
					"[地址："+complaintBean.getAuthorAddr()+"]" +
					"[Email："+complaintBean.getAuthorEmail()+"]" +
							",成功!");
		} catch (SQLException e) {
			logger.error("投诉上报-添加投诉上报|#" +
					"[中心编号："+complaintBean.getStreetId()+"]" +
					"[事件类型："+complaintBean.getQueType()+"]" +
					"[事件内容："+complaintBean.getQueContent()+"]" +
					"[事件发生地："+complaintBean.getQueAddr()+"]" +
					"[服务条线："+complaintBean.getServLine()+"]" +
					"[服务子条线："+complaintBean.getServSubline()+"]" +
					"[投诉人："+complaintBean.getQueAuthor()+"]" +
					"[手机号："+complaintBean.getAuthorPhone()+"]" +
					"[固定电话："+complaintBean.getAuthorTel()+"]" +
					"[身份证："+complaintBean.getAuthorIdcard()+"]" +
					"[地址："+complaintBean.getAuthorAddr()+"]" +
					"[Email："+complaintBean.getAuthorEmail()+"]" +
							",失败!异常：" + e.getMessage());
			throw new BaseException(e,"custom.messages.error.complaint.add.error");
		}
		return queId;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ComplaintBean> queryQueType() throws BaseException {
		List<ComplaintBean> typeLs = null;
		try {
			typeLs = getSqlMapClient().queryForList("portal-complaint.queryQueType");
			logger.info("投诉上报-查询事件类型,成功!");
		} catch (SQLException e) {
			logger.error("投诉上报-查询事件类型,失败!");
			throw new BaseException(e,
					"custom.messages.error.complaint.init.quetype.error");
		}
		return typeLs;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ComplaintBean> queryServLine() throws BaseException {
		List<ComplaintBean> servLineLs = null;
		try {
			servLineLs = getSqlMapClient().queryForList("portal-complaint.queryServLine");
			logger.info("投诉上报-查询服务条线,成功!");
		} catch (SQLException e) {
			logger.error("投诉上报-查询服务条线,失败!");
			throw new BaseException(e,
					"custom.messages.error.complaint.init.servline.error");
		}
		return servLineLs;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ComplaintBean> querySubServLine(String servLineId)
			throws BaseException {
		List<ComplaintBean> subServLineLs = null;
		try {
			subServLineLs = getSqlMapClient().queryForList("portal-complaint.querySubServLine",servLineId);
			logger.info("投诉上报-查询服务子条线,成功!");
		} catch (SQLException e) {
			logger.error("投诉上报-查询服务子条线,失败!");
			throw new BaseException(e,
					"custom.messages.error.complaint.init.subservline.error");
		}
		return subServLineLs;
	}

}
